import akshare as ak

# 使用 akshare 获取当日 A 股行情数据
spot_df = ak.stock_zh_a_spot_em()
# 筛选出当日涨停的股票代码
zt_stocks = spot_df[spot_df['涨跌幅'] >= 9.5]['代码']

# 遍历涨停股票，查找连续上涨天数
for stock_code in zt_stocks:
    hist_df = ak.stock_zh_a_hist(stock_code, start_date="20241101", end_date="20241203")
    # 判断连续上涨天数
    hist_df['涨跌'] = hist_df['涨跌幅']
    hist_df['连续上涨'] = (hist_df['涨跌'] > 0).astype(int)
    hist_df['连续上涨累计'] = hist_df['连续上涨'].cumsum()
    
    # 输出涨停且连续上涨天数超过阈值的股票
    if hist_df.iloc[-1]['连续上涨累计'] > 5:
        print(f"股票代码：{stock_code}，连续上涨天数：{hist_df.iloc[-1]['连续上涨累计']}")
